<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>菜鸟教程(runoob.com)</title>
</head>

<body>
    <p>点击按钮计算数组元素相加后的总和。</p>
    <button onclick="myFunction()">点我</button>
    <p>数组元素总和: <span id="demo"></span></p>

    <script>
        var numbers = [65, 44, 12, 4];
        function getSum(total, num) {
            return total + num; //依次从左向右运算。可以是加法，减法，乘法，除法。
        }
        function myFunction(item) {
            document.getElementById("demo").innerHTML = numbers.reduce(getSum);
        }
    </script>
</body>
</html>